/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CadFornecedor.java
 *
 * Created on 12/11/2011, 16:10:18
 */
package visao;

import endereco.Endereco;
import fachada.FachadaBDR;
import fornecedor.Fornecedor;
import fornecedor.FornecedorNaoCadastradoException;
import java.awt.Color;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JFormattedTextField;
import javax.swing.JOptionPane;
import util.CamposObrigatoriosException;
import util.ErroAcessoRepositorioException;
import util.Util;

/**
 *
 * @author Administrador
 */
public class CadFornecedor extends javax.swing.JFrame {

    /** Creates new form CadSetorEmpresa */
    public CadFornecedor() {
        initComponents();
        this.setLocationRelativeTo(null);

        this.setIconImage(new ImageIcon(getClass().getResource("/Imagens/fornecedor.gif")).getImage());

    }

    public CadFornecedor(int idFornecedor) {
        initComponents();
        this.setLocationRelativeTo(null);
        this.setIconImage(new ImageIcon(getClass().getResource("/Imagens/fornecedor.gif")).getImage());
        try {
            FachadaBDR objFachadaBDR = FachadaBDR.getInstancia();
            // obtendo o Fornecedor
            Fornecedor objFornecedor = objFachadaBDR.procurarFornecedor(idFornecedor);
            Endereco endereco = objFornecedor.getEnderecos();

            jTextField_id_endereco.setText(String.valueOf(endereco.getIdEndereco()));
            jTextField_Rua.setText(endereco.getRua());
            jTextField_Numero.setText(endereco.getNumero());
            jTextField_Bairro.setText(endereco.getBairro());
            jTextField_Cidade.setText(endereco.getCidade());
            jComboBox_Uf.setSelectedItem(endereco.getUf());
            jComboBox_Pais.setSelectedItem(endereco.getPais());
            jTextField_Cep.setText(endereco.getCep());
            jTextField_Telefone.setText(endereco.getTelefone());


            jTextField_idCodigo.setText(String.valueOf(objFornecedor.getIdFornecedor()));
            jTextField_idCodigo.setText(String.valueOf(objFornecedor.getIdFornecedor()));
            jTextField_Nome.setText(objFornecedor.getDescricaoFornecedor());
            jTextField_Contato.setText(objFornecedor.getContato());
            jFormattedTextField_Telefone.setText(objFornecedor.getFoneFornecedor());
            jFormattedTextField_Celular.setText(objFornecedor.getCelularFornecedor());
            jTextField_Email.setText(objFornecedor.getEmailFornecedor());
            jCheckBox_Status.setSelected(objFornecedor.getStatusFornecedor());


        } catch (FornecedorNaoCadastradoException ex) {

            jLabel_Mensagem.setText(ex.getMessage());
            jLabel_Mensagem.setForeground(Color.red);


        } catch (ErroAcessoRepositorioException ex) {

            jLabel_Mensagem.setText(ex.getMessage());
            jLabel_Mensagem.setForeground(Color.red);
        }

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel_Codigo = new javax.swing.JLabel();
        jLabel_Nome = new javax.swing.JLabel();
        jLabel_Telefone = new javax.swing.JLabel();
        jLabel_Celular = new javax.swing.JLabel();
        jLabel_Contato = new javax.swing.JLabel();
        jLabel_Email = new javax.swing.JLabel();
        jCheckBox_Status = new javax.swing.JCheckBox();
        jTextField_Nome = new javax.swing.JTextField();
        jFormattedTextField_Telefone = new javax.swing.JFormattedTextField();
        jFormattedTextField_Celular = new javax.swing.JFormattedTextField();
        jTextField_Contato = new javax.swing.JTextField();
        jTextField_Email = new javax.swing.JTextField();
        jTextField_idCodigo = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jLabel_Rua = new javax.swing.JLabel();
        jTextField_Rua = new javax.swing.JTextField();
        jLabel_Numero = new javax.swing.JLabel();
        jTextField_Numero = new javax.swing.JTextField();
        jTextField_Cep = new javax.swing.JTextField();
        jLabel_Cep = new javax.swing.JLabel();
        jLabel_Bairro = new javax.swing.JLabel();
        jTextField_Bairro = new javax.swing.JTextField();
        jLabel_Cidade = new javax.swing.JLabel();
        jTextField_Cidade = new javax.swing.JTextField();
        jTextField_Telefone = new javax.swing.JTextField();
        jLabel_Uf = new javax.swing.JLabel();
        jComboBox_Uf = new javax.swing.JComboBox();
        jLabel_Pais = new javax.swing.JLabel();
        jComboBox_Pais = new javax.swing.JComboBox();
        jLabel_EndTelefone = new javax.swing.JLabel();
        jTextField_id_endereco = new javax.swing.JTextField();
        jButton_Ok = new javax.swing.JButton();
        jButton_Cancelar = new javax.swing.JButton();
        jLabel_Mensagem = new javax.swing.JLabel();

        setTitle("Fornecedor");
        setResizable(false);

        jLabel_Codigo.setText("Codigo :");

        jLabel_Nome.setText("Nome :");

        jLabel_Telefone.setText("Telefone :");

        jLabel_Celular.setText("Celular :");

        jLabel_Contato.setText("Contato Fornecedor :");

        jLabel_Email.setText("E-mail :");

        jCheckBox_Status.setSelected(true);
        jCheckBox_Status.setText("Ativo");

        jFormattedTextField_Telefone = new JFormattedTextField(Util.setMascara("(##)####-####"));

        jFormattedTextField_Celular = new JFormattedTextField(Util.setMascara("(##)####-####"));

        jTextField_idCodigo.setEnabled(false);
        jTextField_idCodigo.setText("0");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel_Codigo)
                            .addComponent(jLabel_Nome))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTextField_Nome, javax.swing.GroupLayout.PREFERRED_SIZE, 406, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jTextField_idCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jCheckBox_Status)))
                        .addContainerGap(76, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel_Celular)
                            .addComponent(jLabel_Telefone))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jFormattedTextField_Celular)
                            .addComponent(jFormattedTextField_Telefone, javax.swing.GroupLayout.DEFAULT_SIZE, 95, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 88, Short.MAX_VALUE)
                        .addComponent(jLabel_Email)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jTextField_Email, javax.swing.GroupLayout.PREFERRED_SIZE, 217, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(36, 36, 36))))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel_Contato)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jTextField_Contato, javax.swing.GroupLayout.PREFERRED_SIZE, 358, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(76, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel_Codigo)
                        .addComponent(jTextField_idCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jCheckBox_Status)
                        .addGap(18, 18, 18)))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(15, 15, 15)
                        .addComponent(jLabel_Nome))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jTextField_Nome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel_Telefone)
                            .addComponent(jFormattedTextField_Telefone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel_Celular)
                            .addComponent(jFormattedTextField_Celular, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel_Email)
                            .addComponent(jTextField_Email, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel_Contato)
                    .addComponent(jTextField_Contato, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(65, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Fornecedor", jPanel1);

        jLabel_Rua.setText("Rua :");

        jLabel_Numero.setText("Numero :");

        jTextField_Cep = new JFormattedTextField(Util.setMascara("##.###-###"));

        jLabel_Cep.setText("CEP :");

        jLabel_Bairro.setText("Bairro :");

        jLabel_Cidade.setText("Cidade :");

        jTextField_Telefone = new JFormattedTextField(Util.setMascara("(##)####-####"));

        jLabel_Uf.setText("UF :");

        jComboBox_Uf.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "----", "AC", "AL", "AP", "AM", "BA", "CE", "DF", "ES", "GO", "MA", "MT", "MS", "MG", "PA", "PB", "PR", "PE", "PI", "RJ", "RN", "RS", "RO", "RR", "SC", "SP", "SE", "TO" }));

        jLabel_Pais.setText("País :");

        jComboBox_Pais.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-----", "Brasil" }));

        jLabel_EndTelefone.setText("Telefone :");

        jTextField_id_endereco.setVisible(false);
        jTextField_id_endereco.setText("0");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel_Bairro)
                                .addGap(23, 23, 23))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel_Cidade)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextField_Bairro, javax.swing.GroupLayout.PREFERRED_SIZE, 416, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jTextField_Cidade, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addComponent(jLabel_Uf)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jComboBox_Uf, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addGap(126, 126, 126)
                                        .addComponent(jLabel_EndTelefone)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jTextField_Telefone, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addGap(97, 97, 97)
                                        .addComponent(jLabel_Pais)
                                        .addGap(18, 18, 18)
                                        .addComponent(jComboBox_Pais, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                        .addContainerGap(62, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel_Numero, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 184, Short.MAX_VALUE)
                                .addComponent(jLabel_Cep, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(157, 157, 157)
                                .addComponent(jTextField_id_endereco, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 9, Short.MAX_VALUE)
                                .addComponent(jLabel_Rua)
                                .addGap(18, 18, 18)
                                .addComponent(jTextField_Rua, javax.swing.GroupLayout.PREFERRED_SIZE, 427, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(68, 68, 68))))
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addGap(68, 68, 68)
                    .addComponent(jTextField_Numero, javax.swing.GroupLayout.DEFAULT_SIZE, 115, Short.MAX_VALUE)
                    .addGap(131, 131, 131)
                    .addComponent(jTextField_Cep, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(147, 147, 147)))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel_Rua)
                    .addComponent(jTextField_Rua, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(26, 26, 26)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField_id_endereco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel_Numero)
                    .addComponent(jLabel_Cep))
                .addGap(29, 29, 29)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField_Bairro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel_Bairro))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextField_Cidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel_Cidade))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel_EndTelefone)
                        .addComponent(jTextField_Telefone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(27, 27, 27)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel_Uf, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox_Uf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel_Pais)
                    .addComponent(jComboBox_Pais, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(30, Short.MAX_VALUE))
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addGap(34, 34, 34)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addGap(41, 41, 41)
                            .addComponent(jTextField_Cep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addGap(38, 38, 38)
                            .addComponent(jTextField_Numero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addContainerGap(162, Short.MAX_VALUE)))
        );

        jTabbedPane1.addTab("Endereço", jPanel2);

        jButton_Ok.setText("Ok");
        jButton_Ok.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_OkActionPerformed(evt);
            }
        });

        jButton_Cancelar.setText("Cancelar");
        jButton_Cancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_CancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 563, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton_Ok, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jButton_Cancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel_Mensagem, javax.swing.GroupLayout.PREFERRED_SIZE, 337, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 285, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(33, 33, 33)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButton_Ok)
                        .addComponent(jButton_Cancelar))
                    .addComponent(jLabel_Mensagem, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(28, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton_OkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_OkActionPerformed
        // TODO add your handling code here:


        int idFornecedor = Integer.parseInt(jTextField_idCodigo.getText());
        String nome = jTextField_Nome.getText();
        String contato = jTextField_Contato.getText();
        String telefone = jFormattedTextField_Telefone.getText();
        String celular = jFormattedTextField_Celular.getText();
        String email = jTextField_Email.getText();
        boolean status = jCheckBox_Status.isSelected();


        int idEndereco = Integer.parseInt(jTextField_id_endereco.getText());
        String rua = jTextField_Rua.getText();
        String numero = jTextField_Numero.getText();
        String bairro = jTextField_Bairro.getText();
        String cidade = jTextField_Cidade.getText();
        String uf = String.valueOf(jComboBox_Uf.getSelectedItem()).toString();
        String pais = String.valueOf(jComboBox_Pais.getSelectedItem()).toString();
        String cep = jTextField_Cep.getText();
        String tel = jTextField_Telefone.getText();



        try {

            FachadaBDR objFachadaBDR = FachadaBDR.getInstancia();
            Endereco endereco = new Endereco(idEndereco, rua, bairro, cidade, uf, cep, pais, numero);
            Fornecedor fornecedor = new Fornecedor(idFornecedor, contato, email, celular, telefone, nome, status, endereco, null, null);

            if (idFornecedor == 0) {
                objFachadaBDR.cadastrarFornecedor(fornecedor);

                jTextField_Rua.setText("");
                jTextField_Numero.setText("");
                jTextField_Bairro.setText("");
                jTextField_Cidade.setText("");
                jComboBox_Uf.setSelectedIndex(0);
                jComboBox_Pais.setSelectedIndex(0);
                jTextField_Cep.setText("");
                jTextField_Telefone.setText("");
                jTextField_Nome.setText("");
                jTextField_Contato.setText("");
                jFormattedTextField_Telefone.setText("");
                jFormattedTextField_Celular.setText("");
                jTextField_Email.setText("");
                jCheckBox_Status.setSelected(false);


            } else {
                objFachadaBDR.atualizarFornecedor(fornecedor);
            }

            String acao = (idFornecedor == 0) ? "Cadastrado" : "Atualizado";
            jLabel_Mensagem.setText("Fornecedor " + acao + " com Sucesso");
            jLabel_Mensagem.setForeground(Color.BLACK);


        } catch (CamposObrigatoriosException ex) {
            jLabel_Mensagem.setText(ex.getMessage());
            jLabel_Mensagem.setForeground(Color.red);
        } catch (ErroAcessoRepositorioException ex) {
            jLabel_Mensagem.setText(ex.getMessage());
            jLabel_Mensagem.setForeground(Color.red);
        }
    }//GEN-LAST:event_jButton_OkActionPerformed

    private void jButton_CancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_CancelarActionPerformed
        int cancelar = JOptionPane.showConfirmDialog(null, "Deseja Cancelar esta operação?");
        if (cancelar == JOptionPane.YES_OPTION) {
            this.dispose();
        }
    }//GEN-LAST:event_jButton_CancelarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {

        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Loguin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Loguin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Loguin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Loguin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }

        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new CadFornecedor().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton_Cancelar;
    private javax.swing.JButton jButton_Ok;
    private javax.swing.JCheckBox jCheckBox_Status;
    private javax.swing.JComboBox jComboBox_Pais;
    private javax.swing.JComboBox jComboBox_Uf;
    private javax.swing.JFormattedTextField jFormattedTextField_Celular;
    private javax.swing.JFormattedTextField jFormattedTextField_Telefone;
    private javax.swing.JLabel jLabel_Bairro;
    private javax.swing.JLabel jLabel_Celular;
    private javax.swing.JLabel jLabel_Cep;
    private javax.swing.JLabel jLabel_Cidade;
    private javax.swing.JLabel jLabel_Codigo;
    private javax.swing.JLabel jLabel_Contato;
    private javax.swing.JLabel jLabel_Email;
    private javax.swing.JLabel jLabel_EndTelefone;
    private javax.swing.JLabel jLabel_Mensagem;
    private javax.swing.JLabel jLabel_Nome;
    private javax.swing.JLabel jLabel_Numero;
    private javax.swing.JLabel jLabel_Pais;
    private javax.swing.JLabel jLabel_Rua;
    private javax.swing.JLabel jLabel_Telefone;
    private javax.swing.JLabel jLabel_Uf;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextField jTextField_Bairro;
    private javax.swing.JTextField jTextField_Cep;
    private javax.swing.JTextField jTextField_Cidade;
    private javax.swing.JTextField jTextField_Contato;
    private javax.swing.JTextField jTextField_Email;
    private javax.swing.JTextField jTextField_Nome;
    private javax.swing.JTextField jTextField_Numero;
    private javax.swing.JTextField jTextField_Rua;
    private javax.swing.JTextField jTextField_Telefone;
    private javax.swing.JTextField jTextField_idCodigo;
    private javax.swing.JTextField jTextField_id_endereco;
    // End of variables declaration//GEN-END:variables
}
